home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / b_bbs.c < prev    next >
C/C++ Source or Header  |  1989-03-11  |  9KB  |  260 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                BinkleyTerm BBS / UUCP Session Initiator                  */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  27. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  28. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  29. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  30. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /*    The Authors can be reached at the following addresses:                */
  34. /*                                                                          */
  35. /*    Robert C. Hartman                      Vincent E. Perriello           */
  36. /*    Spark Software                         VEP Software                   */
  37. /*    427-3 Amherst Street                   111 Carroll Street             */
  38. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  39. /*    Nashua, NH 03061                                                      */
  40. /*                                                                          */
  41. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  42. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  43. /*                                                                          */
  44. /*    Please feel free to contact us at any time to share your comments     */
  45. /*    about our software and/or licensing policies.                         */
  46. /*                                                                          */
  47. /*--------------------------------------------------------------------------*/
  48.  
  49. #include <stdio.h>
  50. #include <signal.h>
  51. #include <ctype.h>
  52. #include <conio.h>
  53. #include <string.h>
  54. #include <process.h>
  55.  
  56. #define WAZOO_SECTION
  57. #define MATRIX_SECTION
  58.  
  59. #include "com.h"
  60. #include "xfer.h"
  61. #include "zmodem.h"
  62. #include "keybd.h"
  63. #include "sbuf.h"
  64. #include "sched.h"
  65. #include "externs.h"
  66. #include "prototyp.h"
  67.  
  68. void BBSexit ()
  69. {
  70.    int retval;
  71.    int xit = 0;
  72.    char command[80];
  73.    FILE *bbsbatch;
  74.    long t1, t2;
  75.  
  76.    if (BBSnote != NULL)
  77.       {
  78.       sendbanner ("\r\n");                       /* Start with newline    */
  79.       sendbanner (BBSnote);                      /* Tell user we're going */
  80.       sendbanner ("\r\n");                       /* End it with a newline */
  81.       }
  82.  
  83.    t1 = timerset (50);
  84.    t2 = timerset (400);
  85.  
  86.    /* Wait for output complete, 4 seconds, or carrier loss */
  87.  
  88.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  89.       ;
  90.  
  91.    /* Make sure we waited at least 1/2 second */
  92.    while (CARRIER && !timeup (t1))
  93.       ;
  94.  
  95.    /* Now if there is no carrier bag it */
  96.    if (!CARRIER)
  97.       {
  98.       status_line ("!Lost Caller");
  99.       return;
  100.       }
  101.  
  102.    ++hist.bbs_calls;
  103.    sb_move (historywin, HIST_BBS_ROW, HIST_COL);
  104.    sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  105.    sb_puts (historywin, junk);
  106.  
  107.    if (strnicmp (BBSopt, "batch", 5) == 0)       /* if BBS flag is "batch" */
  108.       {
  109.       strcpy (command, "BBSBATCH.BAT");          /* Batch file name        */
  110.       unlink (command);                          /* Delete old copies      */
  111.       if ((bbsbatch = fopen (command, "a")) == NULL)    /* Try to open it  */
  112.          {
  113.          status_line ("!Couldn't open BBSBATCH.BAT");
  114.          return;
  115.          }
  116.       errno = 0;
  117.       fprintf (bbsbatch, "SPAWNBBS %u %d %d %s\n",
  118.                cur_baud, port_ptr + 1, time_to_next (), mdm_reliable);
  119.       fclose (bbsbatch);
  120.       if (errno)
  121.          {
  122.          status_line ("!Trouble writing BBSBATCH.BAT");
  123.          return;
  124.          }
  125.       xit = 1;
  126.       }
  127.  
  128.    if ((strnicmp (BBSopt, "exit", 4) == 0) || (xit))    /* "exit" or "batch" ??   */
  129.       {
  130.       retval = cur_baud / 100;
  131.       status_line (":Exiting to BBS with Errorlevel %u", retval);
  132.       if (vfossil_installed)
  133.          vfossil_close ();
  134.  
  135.       if (!share)                                /* Turn off FOSSIL,       */
  136.          MDM_DISABLE ();                         /* if need be             */
  137.       write_sched ();
  138.       exit (retval);                             /* and exit with error    */
  139.       }
  140.  
  141.    if (strnicmp (BBSopt, "spawn", 5) == 0)       /* if BBS flag is "spawn" */
  142.       {
  143.       status_line (":Spawning BBS");
  144.       gotoxy (0, 23);
  145.       sprintf (command, "SPAWNBBS %u %d %d %s",
  146.                cur_baud, port_ptr + 1, time_to_next (), mdm_reliable);
  147.       close_up ();
  148.  
  149.       /* Run the BBS */
  150.       b_spawn (command);
  151.  
  152.       come_back ();
  153.       status_line (":Returned from BBS");
  154.       }
  155. }
  156.  
  157. void close_up ()
  158. {
  159.    if (!share)
  160.        MDM_DISABLE ();
  161.  
  162.    vfossil_close ();
  163.  
  164.    /* Close the log file */
  165.    if (status_log != NULL)
  166.       fclose (status_log);
  167. }
  168.  
  169. void come_back ()
  170. {
  171.    /* Re-enable ourselves */
  172.    if (Cominit (port_ptr) != 0x1954)
  173.       {
  174.       cprintf ("\r\nDarn!  The FOSSIL seems to have gone away!  Exiting\r\n");
  175.       exit (1);
  176.       }
  177.  
  178.    if (status_log != NULL)
  179.       {
  180.       if ((status_log = fopen (log_name, "at")) == NULL)
  181.          {
  182.          cprintf ("\r\nCannot re-open logfile\r\n");
  183.          }
  184.       }
  185.  
  186.    MDM_ENABLE (btypes[baud].rate);
  187.    vfossil_init ();
  188.    if (fullscreen && un_attended)
  189.       {
  190.       scr_printf ("\033[H\033[2J");
  191.       sb_dirty ();
  192.       opening_banner ();
  193.       mailer_banner ();
  194.       sb_show ();
  195.       }
  196. }
  197.  
  198.  
  199. void UUCPexit (n)
  200. int n;         /* UUCP Errorlevel value */
  201. {
  202.    char command[80];
  203.    FILE *mailbatch;
  204.    long t1, t2, timerset ();
  205.  
  206.    if (MAILnote != NULL)
  207.       {
  208.       sendbanner ("\r\n");                       /* Start with newline */
  209.       sendbanner (MAILnote);                     /* Say it's mail time */
  210.       sendbanner ("\r\n");                       /* End with a newline */
  211.       }
  212.  
  213.    t1 = timerset (50);
  214.    t2 = timerset (400);
  215.  
  216.    /* Wait for output complete, 4 seconds, or carrier loss */
  217.  
  218.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  219.       ;
  220.  
  221.    /* Make sure we waited at least 1/2 second */
  222.    while (CARRIER && !timeup (t1))
  223.       ;
  224.  
  225.    /* Now if there is no carrier bag it */
  226.    if (!CARRIER)
  227.       {
  228.       status_line ("!Lost Caller");
  229.       return;
  230.       }
  231.  
  232.    strcpy (command, "MAILBAT.BAT");              /* Batch file name   */
  233.    unlink (command);                             /* Delete old copies */
  234.    if ((mailbatch = fopen (command, "a")) == NULL)      /* Try to open it    */
  235.       {
  236.       status_line ("!Couldn't open MAILBAT.BAT");
  237.       return;
  238.       }
  239.    errno = 0;
  240.    fprintf (mailbatch, "EXTMAIL %u %d %d %d %s\n",
  241.             cur_baud, port_ptr + 1, time_to_next (), n, mdm_reliable);
  242.    fclose (mailbatch);
  243.    if (errno)
  244.       {
  245.       status_line ("!Trouble writing MAILBAT.BAT");
  246.       return;
  247.       }
  248.  
  249.    status_line (":Exiting to external mailer with Errorlevel %u", n);
  250.  
  251.    if (vfossil_installed)
  252.       vfossil_close ();
  253.  
  254.    if (!share)                                   /* Turn off FOSSIL,          */
  255.       MDM_DISABLE ();                            /* if need be                */
  256.  
  257.    write_sched ();                               /* Save scheduler info       */
  258.    exit (n);                                     /* and exit with UUCP error  */
  259. }
  260.